home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Mac OS Development Toolkit / Automation Essentials 2.3.0 / Host Automation Folder / VU External Tool libs / IvyOperations.Lib < prev    next >
Encoding:
Text File  |  1998-03-19  |  8.1 KB  |  236 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:    IvyOperations.Lib
  5. #
  6. #    Contains:    Tasks which extend the basic functionality of the Ivy.vulib.
  7. #
  8. #    Written by:    KTA
  9. #
  10. #    Copyright:    © 1993-1997 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #        1.4.0    2/12/97        JAS        Added 'vers' resources to library.
  19. #                                    These should always match tool version when tool is revved.
  20. #     <1.0.3>     2/16/95    KTA        _Ivy() - Replaced with new version of standard template which
  21. #                                    fixes some problems.
  22. #     <1.0.2>     1/19/95    KTA        Changed the name of ExceptionHandler() to ExceptionDispatcher().
  23. #     <1.0.1>     1/13/95    KTA        Changed parameter name.
  24. #         <1>     1/12/95    KTA        Created - first checked in.
  25. #
  26. # ****************************************************************************
  27. #
  28.  
  29.  
  30. ########################################################################
  31. #                            External libraries 
  32. #=======================================================================
  33. Libraries "Ivy Tool Declaration.vulib", "Ivy.vuLib", "Output.Lib", "String.Lib", "ExceptionHandling.Lib";
  34.  
  35. #########################################################################
  36. #        _Ivy(pOnTheTarget := true)
  37. #========================================================================
  38. # Author:        KTA 
  39. # Description:    Does the exception handling for the Ivy.  All high level tasks
  40. #                should call this routine for file tool services.  Handles initialization
  41. #                of tool automatically.
  42. # Parameters:    pServiceOrTask - Name of the Service
  43. #                pParamList - List of parameters
  44. #                pOnTarget - Flag to indicate whether the service should be performed 
  45. #                            the host or the target.  1 = target/0 = host.
  46. # Returns:        Whatever the file tool returns
  47. # Examples:        _Ivy('LocateImage', {'fileName'},1);
  48. # Assumptions:    None 
  49. #========================================================================
  50. # History:
  51. # KTA    12/12/94    Only match the mouse if pOnTarget is true
  52. # KTA    2/16/95        coerce pOnTarget to be either true or false, Temporarily
  53. #                    turn commandexceptions off, check scripterror, reset 
  54. #                    commandexceptions, and if necessary throw scripterror 
  55. #########################################################################
  56. TASK _Ivy(pServiceOrTask, pParamList := {}, pOnTarget := true, pIsRetry := 0)
  57. begin
  58.     Try
  59.     begin
  60.         returnVal := undefined;
  61.         ParamType := TypeOf(pServiceOrTask);
  62.         
  63.         if (ParamType = 'string') # Service Call
  64.         begin
  65.             if (pOnTarget)
  66.                 pOnTarget := true;
  67.             else
  68.                 pOnTarget := false;
  69.             if not(global gIvyInitFlag = pOnTarget)
  70.             begin
  71.                 try
  72.                 begin
  73.                     temp := CommandExceptions(0);
  74.                     IvyInit :=  Ivy("Initialize", pOnTarget );         # initialize Ivy
  75.                     InitError := Scripterror();
  76.                     CommandExceptions(temp);
  77.                     if (IvyInit[1] <> 0)        # If error
  78.                     begin
  79.                         println "Ivy error ( ", IvyInit[1], ", ",  IvyInit[3] , " )";
  80.                         gIvyInitFlag := undefined;
  81.                         if (CommandExceptions())
  82.                             throw InitError;
  83.                         return(IvyInit);
  84.                     end;
  85.                     else
  86.                         gIvyInitFlag := pOnTarget;
  87.                 end;
  88.                 catch theErr
  89.                 begin
  90.                     ExceptionDispatcher(theErr);
  91.                     return(IvyInit);
  92.                 end;
  93.             end;
  94.  
  95.             try
  96.             begin
  97.                 NumParams := Card(pParamList);
  98.                 switch NumParams
  99.                 begin
  100.                     case 0:                    # 0 parameters
  101.                         returnVal := Ivy(pServiceOrTask); 
  102.                     case 1:                    # 1 parameter
  103.                         returnVal := Ivy(pServiceOrTask, pParamList[1]); 
  104.                     case 2:                    # 2 parameters
  105.                         returnVal := Ivy(pServiceOrTask, pParamList[1], pParamList[2]); 
  106.                     case 3:                    # 3 parameters
  107.                         returnVal := Ivy(pServiceOrTask, pParamList[1], pParamList[2], pParamList[3]); 
  108.                     case 4:                    # 4 parameters
  109.                         returnVal := Ivy(pServiceOrTask, pParamList[1], pParamList[2], pParamList[3], pParamList[4]); 
  110.                     case 5:                    # 5 parameters
  111.                         returnVal := Ivy(pServiceOrTask, pParamList[1], pParamList[2], pParamList[3], pParamList[4], pParamList[5]); 
  112.                     case 6:                    # 6 parameters
  113.                         returnVal := Ivy(pServiceOrTask, pParamList[1], pParamList[2], pParamList[3], pParamList[4], pParamList[5], pParamList[6]); 
  114.                     default:                # error
  115.                         println "Error - unsupported number of parameters - {NumParams}";
  116.                 end;
  117.         
  118.                 if (returnVal[1] <> 0)        # If error
  119.                 begin
  120.                     if(returnVal[1] = -1) and not (pIsRetry)    # Not initialized, and haven't retried already
  121.                     begin
  122.                         global gIvyInitFlag := undefined;
  123.                         returnVal := _Ivy(pServiceOrTask, pParamList, pOnTarget, 1);
  124.                     end;
  125.                 end;
  126.                 else if(pServiceOrTask = 'Quit')        # Reset the global gIvyInitFlag when we quit
  127.                     global gIvyInitFlag := undefined;
  128.             
  129.             end;
  130.             catch theErr
  131.             begin
  132.                 if(theErr = -1220) and not (pIsRetry)
  133.                 begin
  134.                     global gIvyInitFlag := undefined;
  135.                     returnVal := _Ivy(pServiceOrTask, pParamList, pOnTarget, 1);
  136.                 end;
  137.                 else
  138.                     exceptionDispatcher(theErr);
  139.             end;
  140.         end;
  141.         else if(ParamType = 'task')
  142.         begin
  143.             NumParams := Card(pParamList);
  144.             switch NumParams 
  145.             begin
  146.                 case 0:                    # 0 parameters
  147.                     returnVal := call (pServiceOrTask); 
  148.                 case 1:                    # 1 parameter
  149.                     returnVal := call (pServiceOrTask, pParamList[1]); 
  150.                 case 2:                    # 2 parameters
  151.                     returnVal := call (pServiceOrTask, pParamList[1], pParamList[2]); 
  152.                 case 3:                    # 3 parameters
  153.                     returnVal := call (pServiceOrTask, pParamList[1], pParamList[2], pParamList[3]); 
  154.                 case 4:                    # 4 parameters
  155.                     returnVal := call (pServiceOrTask, pParamList[1], pParamList[2], pParamList[3], pParamList[4]); 
  156.                 case 5:                    # 5 parameters
  157.                     returnVal := call (pServiceOrTask, pParamList[1], pParamList[2], pParamList[3], pParamList[4], pParamList[5]); 
  158.                 case 6:                    # 6 parameters
  159.                     returnVal := call (pServiceOrTask, pParamList[1], pParamList[2], pParamList[3], pParamList[4], pParamList[5], pParamList[6]); 
  160.                 default:                # error
  161.                     println "Error - unsupported number of parameters - {NumParams}";
  162.             end;
  163.         end;
  164.         
  165.         if(pOnTarget)            # To cause target errors to throw if Xtools are called
  166.             match[mouse];
  167.             
  168.         return(returnVal);
  169.     end;
  170.     Catch theError
  171.         ExceptionDispatcher(theError);
  172. end;
  173.  
  174. #########################################################################
  175. #        InitIvy(pOnTheTarget := true)
  176. #========================================================================
  177. # Author:        KTA 
  178. # Description:    Initializes the Ivy 
  179. # Parameters:    pOnTheTarget - True if you want to launch the Ivy on  
  180. #                                the target machine. False if on the Host.
  181. # Returns:        0 - Couldn't initialize
  182. #                1 - Init On Target
  183. #                2 - Init On Host
  184. # Examples:        InitIvy();
  185. # Assumptions:    None 
  186. #========================================================================
  187. # History:
  188. # KTA    12/12/94    Updated to call _Ivy()
  189. #########################################################################
  190. TASK InitIvy(pOnTheTarget := true)
  191. begin
  192.     returnVal := 0;
  193.     IvyInit :=  _Ivy( "Initialize", {pOnTheTarget} );         # Launch Ivy
  194.     if IvyInit[1] <> 0                                    # If error during initialization,
  195.     begin
  196.         println "Ivy could not be initialized";        # print error
  197.         println "Error ", IvyInit[1], ". ",  IvyInit[3] ;
  198.     end;
  199.     else
  200.     begin
  201.         if (pOnTheTarget)        # Was it on the Target
  202.             returnVal := 1;
  203.         else                     # Or was it on the Host
  204.             returnVal := 2;
  205.  
  206.     end;
  207.     return(returnVal);
  208. end;
  209. #########################################################################
  210. #        QuitIvy()
  211. #========================================================================
  212. # Author:        KTA 
  213. # Description:    Quits  Ivy 
  214. # Parameters:    none
  215. # Returns:        0 - Couldn't Quit
  216. #                1 - Quit Successfully
  217. # Examples:        QuitIvy();
  218. # Assumptions:    None 
  219. #========================================================================
  220. # History:
  221. # KTA    1/6/95    Created
  222. #########################################################################
  223. TASK QuitIvy(pOnTheTarget := true)
  224. begin
  225.     IvyQuit :=  _Ivy( "Quit");         # Quit Ivy
  226.     if (IvyQuit[1] <> 0)                                    # If error during initialization,
  227.     begin
  228.         println "Ivy could not be quit";        # print error
  229.         println "Error ", IvyQuit[1], ". ",  IvyQuit[3] ;
  230.         returnVal := 0;    # Error
  231.     end;
  232.     else
  233.         returnVal := 1;    # Success
  234.     return(returnVal);
  235. end;
  236.